package com.zzyl.nursing.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zzyl.nursing.domain.Reservation;
import com.zzyl.nursing.vo.TimeSlotCountVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface MemberReservationMapper extends BaseMapper<Reservation> {
    Integer countTodayCancelled(
                                  @Param("startTime") LocalDateTime startTime,
                                  @Param("endTime") LocalDateTime endTime,
                                  @Param("cancelStatus") Integer cancelStatus);

//
//    @Select(" SELECT " +
//            "        time" +
//            "        COUNT(1) AS count " +
//            "    FROM reservation" +
//            "    WHERE " +
//            "        DATE(time) = CURDATE() " +
//            "        AND TIME(time) BETWEEN '08:00:00' AND '18:00:00'" +
//            "    GROUP BY time")

    @Select("SELECT\n" +
            "            time," +
            "    COUNT(1) AS count" +
            "    FROM reservation" +
            "    WHERE" +
            "    DATE(time) = CURDATE()" +
            "    AND TIME(time) BETWEEN '08:00:00' AND '18:00:00'" +
            "    AND status NOT IN (2, 3)  " +
            "    GROUP BY time;")

    List<TimeSlotCountVo> countReservedByTime();

    int updateExpiredReservations();
}
